package kr.hkit.androidcomplete02.ch12;

import kr.hkit.androidcomplete02.R;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridLayout;
import android.widget.GridView;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {
	
	private Context myContext;
	
	int[] picture = {
			R.drawable.gang1,
			R.drawable.gang2,
			R.drawable.gang3,
			R.drawable.gang4
	};
	
	public ImageAdapter(Context c){
		myContext = c;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return 100;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return picture[position %4];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imageView;
		if(convertView == null){
			imageView = new ImageView(myContext);
			imageView.setLayoutParams(new GridView.LayoutParams(100, 150));
			imageView.setAdjustViewBounds(false);
			imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
		}else{
			imageView = (ImageView) convertView;
		}
		imageView.setImageResource(picture[position % 4]);
		return imageView;
	}

}
